﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

// Additional Libraries
using FindMe.FindMeFriendServiceReference;

namespace LocalDatabase.Model
{
    [Table]
    public class FindMeFriend : INotifyPropertyChanged, INotifyPropertyChanging
    {

        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _version;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion

        // Define ID: private field, public property, and database column.
        private Guid _contactId;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public Guid ContactID
        {
            get { return _contactId; }
            set
            {
                if (_contactId != value)
                {
                    NotifyPropertyChanging("contactID");
                    _contactId = value;
                    NotifyPropertyChanged("contactID");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _phoneNumber;

        [Column]
        public string PhoneNumber
        {
            get { return _phoneNumber; }
            set
            {
                if (_phoneNumber != value)
                {
                    NotifyPropertyChanging("PhoneNumber");
                    _phoneNumber = value;
                    NotifyPropertyChanged("PhoneNumber");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _userName;

        [Column(CanBeNull = false)]
        public string UserName
        {
            get { return _userName; }
            set
            {
                if (_userName != value)
                {
                    NotifyPropertyChanging("UserName");
                    _userName = value;
                    NotifyPropertyChanged("UserName");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _name;

        [Column(CanBeNull = false)]
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    NotifyPropertyChanging("Name");
                    _name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _email;

        [Column(CanBeNull = false)]
        public string Email
        {
            get { return _email; }
            set
            {
                if (_email != value)
                {
                    NotifyPropertyChanging("Email");
                    _email = value;
                    NotifyPropertyChanged("Email");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _lastLocation;

        [Column]
        public string LastLocation
        {
            get { return _lastLocation; }
            set
            {
                if (_lastLocation != value)
                {
                    NotifyPropertyChanging("LastLocation");
                    _lastLocation = value;
                    NotifyPropertyChanged("LastLocation");
                }
            }
        }
    }


    [Table]
    public class FavoriteLocation : INotifyPropertyChanged, INotifyPropertyChanging
    {

        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _Version;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion


        // Define ID: private field, public property, and database column.
        private int _id;

        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int ID
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    NotifyPropertyChanging("ID");
                    _id = value;
                    NotifyPropertyChanged("ID");
                }
            }
        }

        // Define item name: private field, public property, and database column.
        private string _name;

        [Column]
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name != value)
                {
                    NotifyPropertyChanging("Name");
                    _name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }



        //// Define item name: private field, public property, and database column.
        //private string _image;

        //[Column]
        //public string image
        //{
        //    get { return _image; }
        //    set
        //    {
        //        if (_image != value)
        //        {
        //            NotifyPropertyChanging("image");
        //            _image = value;
        //            NotifyPropertyChanged("image");
        //        }
        //    }
        //}

        // Define completion value: private field, public property, and database column.
        private string _location;

        [Column]
        public string Location
        {
            get { return _location; }
            set
            {
                if (_location != value)
                {
                    NotifyPropertyChanging("Location");
                    _location = value;
                    NotifyPropertyChanged("Location");
                }
            }
        }
    }

    public class FindMeDataContext : DataContext
    {
        // Pass the connection string to the base class.
        public FindMeDataContext() : base("Data Source=isostore:/FindMeDB.sdf") { }

        public Table<FindMeFriend> FindMeFriends;

        public Table<FavoriteLocation> FavoriteLocations;
    }
}